package com.jeespring.algorithm.sort;

import com.alibaba.fastjson.JSON;

/**
 * @Title: InsertSort
 * @Description:
 * @Author 张朝阳
 * @Date 2020/11/25 16:27
 */
public class InsertionSort {
    public static void main(String[] args) {
        int arr[] = {9,6,16,13,36,15,39,20,10};
        sort(arr);
        System.out.println(JSON.toJSONString(arr));
    }
    public static void sort(int arr[]){
        // 从小到大
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = i+1; j > 1; j--) {
                if (arr[j] < arr[j-1]) {
                    int temp = arr[j-1];
                    arr[j-1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
    }
}
